package com.chensf.studydemo.guide.design

import android.os.Bundle
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.activity_coordinator_demo.*

class CoordinatorLayoutDemo : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_coordinator_demo)
//        recyclerView.layoutManager = LinearLayoutManager(this)
//        recyclerView.adapter = object : RecyclerView.Adapter<MyViewHolder>() {
//            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder =
//                MyViewHolder(layoutInflater.inflate(R.layout.view_simple_list_item, parent,false))
//
//            override fun getItemCount(): Int = 30
//
//            override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
//                (holder.itemView as TextView).apply {
//                    text = "content $position"
//                }
//            }
//
//        }

//        setSupportActionBar(toolbar)

        var isToolbarShown = false
        // scroll change listener begins at Y = 0 when image is fully collapsed
        plant_detail_scrollview.setOnScrollChangeListener(
            NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, _ ->

                // User scrolled past image to height of toolbar and the title text is
                // underneath the toolbar, so the toolbar should be shown.
                val shouldShowToolbar = scrollY > toolbar.height

                // The new state of the toolbar differs from the previous state; update
                // appbar and toolbar attributes.
                if (isToolbarShown != shouldShowToolbar) {
                    isToolbarShown = shouldShowToolbar

                    // Use shadow animator to add elevation if toolbar is shown
                    appbar.isActivated = shouldShowToolbar

                    // Show the plant name if toolbar is shown
                    toolbar_layout.isTitleEnabled = shouldShowToolbar
                }
            }
        )
    }
}